package tech.dort.dortware.impl.modules.exploit;

import com.google.common.eventbus.Subscribe;
import net.minecraft.network.play.client.C02PacketUseEntity;
import net.minecraft.network.play.client.C03PacketPlayer;
import tech.dort.dortware.api.module.Module;
import tech.dort.dortware.api.module.ModuleData;
import tech.dort.dortware.impl.events.PacketEvent;
import tech.dort.dortware.impl.utils.inventory.InventoryUtils;

public class InfiniteDurability extends Module {

    private boolean attacked;

    public InfiniteDurability(ModuleData moduleData) {
        super(moduleData);
    }

    @Subscribe
    public void onPacket(PacketEvent event) {
        if (event.getPacket() instanceof C02PacketUseEntity) {
            InventoryUtils.swap(9, mc.thePlayer.inventory.currentItem);
            InventoryUtils.swap(9, mc.thePlayer.inventory.currentItem);
            attacked = true;
        }

        if (event.getPacket() instanceof C03PacketPlayer) {
            if (attacked) {
                InventoryUtils.swap(9, mc.thePlayer.inventory.currentItem);
                InventoryUtils.swap(9, mc.thePlayer.inventory.currentItem);
                attacked = false;
            }
        }
    }
}
